package com.lineage.server.serverpackets;

public class S_ServerMessage extends ServerBasePacket {
  private byte[] _byte;
  
  public S_ServerMessage(String msg) {
    this._byte = null;
    writeC(81);
    writeC(0);
    writeD(0);
    writeS(msg);
  }
  
  public S_ServerMessage(String name, int color) {
    this._byte = null;
    writeC(243);
    writeC(color);
    writeS(name);
  }
  
  public S_ServerMessage(int type) {
    this._byte = null;
    writeC(71);
    writeH(type);
    writeC(0);
  }
  
  public S_ServerMessage(int type, String msg1) {
    this._byte = null;
    buildPacket(type, new String[] { msg1 });
  }
  
  public S_ServerMessage(int type, String msg1, String msg2) {
    this._byte = null;
    buildPacket(type, new String[] { msg1, msg2 });
  }
  
  public S_ServerMessage(int type, String msg1, String msg2, String msg3) {
    this._byte = null;
    buildPacket(type, new String[] { msg1, msg2, msg3 });
  }
  
  public S_ServerMessage(int type, String msg1, String msg2, String msg3, String msg4) {
    this._byte = null;
    buildPacket(type, new String[] { msg1, msg2, msg3, msg4 });
  }
  
  public S_ServerMessage(int type, String msg1, String msg2, String msg3, String msg4, String msg5) {
    this._byte = null;
    buildPacket(type, new String[] { msg1, msg2, msg3, msg4, msg5 });
  }
  
  public S_ServerMessage(int type, String[] info) {
    this._byte = null;
    buildPacket(type, info);
  }
  
  private void buildPacket(int type, String[] info) {
    writeC(71);
    writeH(type);
    if (info == null) {
      writeC(0);
    } else {
      writeC(info.length);
      int i = 0;
      while (i < info.length) {
        writeS(info[i]);
        i++;
      } 
    } 
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
